package com.thesis.object;

/**
 * Session singleton class
 * 
 * save login info to session
 * 
 * @author NgocTuyen
 *
 */
public class Session {
	//singleton variable
	private static Session session = new Session();
	
	//session variable
	private int id;
	private String username;
	private String ci_session;
	private int role;
	
	/**
	 * Constructor function
	 * 
	 * Constructor
	 * 
	 * @access private
	 * 
	 * @param null
	 * 
	 * @return null
	 */
	private Session(){
		
	}
	
	/**
	 * getInstance static function
	 * 
	 * get singleton variable
	 * 
	 * @access public
	 * 
	 * @param null
	 * 
	 * @return Session
	 */
	public static Session getInstance(){
		if (session == null) session = new Session();
		return session;
	}
	
	/**
	 * setSession function
	 * 
	 * set user info to session
	 * 
	 * @access public
	 * 
	 * @param id id of current user
	 * @param username username of current user
	 * @param ci_session session id of current login
	 * @param role role of current user
	 * 
	 * @return void
	 */
	public void setSession(int id, String username, String ci_session, int role){
		this.id = id;
		this.username = username;
		this.ci_session = ci_session;
		this.role = role;
	}
	
	/**
	 * getId function
	 * 
	 * get id of current user
	 * 
	 * @access public
	 * 
	 * @param null
	 * 
	 * @return int
	 *  + id of current user
	 */
	public int getId(){
		return id;
	}
	
	/**
	 * getUserName function
	 * 
	 * get username of current user
	 * 
	 * @access public
	 * 
	 * @param null
	 * 
	 * @return String
	 *  + username of current user
	 */
	public String getUserName(){
		return username;
	}
	
	/**
	 * getCI_Session function
	 * 
	 * get ci_session of current login
	 * 
	 * @access public
	 * 
	 * @param null
	 * 
	 * @return String
	 *  + ci_session of current login
	 */
	public String getCI_Session(){
		return ci_session;
	}
	
	/**
	 * getRole function
	 * 
	 * get role of current user
	 * 
	 * @access public
	 * 
	 * @param null
	 * 
	 * @return int
	 *  + role of current user
	 */
	public int getRole(){
		return role;
	}
	
	public void clear(){
		session = null;
	}
}
